package com.app.layertree;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        show();
    }

    private void show() {
        getSupportFragmentManager().beginTransaction().add(R.id.fragment_contain, new MyContactsFragment(), "test").commit();
    }

    private void hide() {
        if (getSupportFragmentManager().findFragmentByTag("test") != null)
            getSupportFragmentManager().beginTransaction().remove(getSupportFragmentManager().findFragmentByTag("test")).commit();
    }

    @Override
    public void onBackPressed() {
        hide();
        super.onBackPressed();
    }
}